/*
  ID: nemokin1
  PROG: runround
  LANG: C++
*/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
 
using namespace std;
 
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=b;--i)
#define FOREACH(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define ALL(c) (c).begin(),(c).end()
 
#define debug(x) cerr<< #x << " = " << (x) << "\n";
#define debugv(v) cerr << #v << " = "; FOREACH(it,v) cerr << *it <<","; cerr << "\n";
#define SIZE(a)  (int(a.size()))
 
template<typename T> inline void checkMax(T& a, T b) {if (b>a) a=b;}
template<typename T> inline void checkMin(T& a, T b) {if (b<a) a=b;}
 
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef long double ld;
const int INF = 1000000000;

LL N;
bool isvalid(string num);
void dfs(string s, int *sta, int beg, int len)
{
    if(beg == len){
	LL n;
	stringstream ss(s.substr(0,len));
	ss >> n;
	if(n > N && isvalid(s.substr(0,len))) {
	    cout<<n<<endl;
	    exit(0);
	}
	return;
    }
    for(int i = 1; i <= 9; i++){
	if(sta[i] == 1) continue;
	s[beg] = '0'+i;
	sta[i] = 1;
	dfs(s,sta,beg+1,len);
	sta[i] = 0;
    }
}



bool isvalid(string num)
{
    int cn[10];
    memset(cn,0,sizeof(cn));
    bool test = true;
    for(int t = 0; t < num.size(); t++){
	char c = num[t];
	if(c == '0' || cn[c-'0']++ >= 1) {
	    test = false;
	    break;
	}
    }
    if(!test) return false;
    int sz = num.size();
    char beg = num[0];
    int ind = (beg-'0')%sz;
    memset(cn,0,sizeof(cn));
    for(;;){
	char now = num[ind];
	if(now == beg) break;
	if(cn[now-'0']++ == 1) break;
	ind = (ind+now-'0')%sz;
    }
    bool valid = true;
    for(int t = 1; t < sz; t++){
	if(cn[num[t]-'0'] != 1) {
	    valid = false;
	    break;
	}
    }
    return valid;
}

int main() {
    freopen("runround.in","r",stdin);freopen("runround.out","w",stdout);
    cin >> N;
    string s(10,'0');
    int sta[10];
    memset(sta,0,sizeof(sta));

    stringstream ss;
    ss << N;
    string tq = ss.str();
    
    for(int i = tq.size(); i <= 9; i++){
	dfs(s,sta,0,i);
    }
    exit(0);
}
